home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
tcbeep.arc
/
BEEP.C
next >
Wrap
Text File
|
1988-03-24
|
3KB
|
76 lines
/*************************************************************************
* Turbo Pascal includes nice built in 'sound' and 'nosound' functions. *
* I used these functions in all of my programs to produce a pleasant *
* 'diddle-diddle' sound when a user makes an incorrect data entry. I *
* find this much more pleasant than the ASCII 7 'beeeep' from the PC's *
* speaker. Unfortunately, Turbo C does not have any built in speaker *
* control (at least none that I have found yet) and all of the public *
* domain speaker controls are pretty difficult to implement for such a *
* trivial application ('diddle-diddle'). The following code ('beep') *
* requires only 20 lines and allows you to produce a speaker tone for *
* essentially any length of time. Please refer to Peter Norton's ex- *
* cellent book ("Programmer's Guide to the IBM-PC, page 148 to 152 for *
* a lucid explanation and examples in BASICA. The 'main' given here *
* a very short and stupid demo. To get a 'diddle-diddle' sound, try: *
* beep( 1000, 10000 ); *
* beep( 600, 5000 ); *
* I hope you find this routine useful... - mike groh, Lexington, MA *
**************************************************************************/
int beep( freq, duration )
int freq; /* frequency to play */
int duration; /* how long (clock ticks) to sound */
{
int count;
int old, new;
count = ( 1193280 / freq );
/* the 8253 timer is on port 67 */
outport( 67, 182 ); /* get timer ready */
outport( 66, count % 256 ); /* load low order byte */
outport( 66, count / 256 ); /* load high order byte */
old = inport( 97 ); /* speaker is on port 97 */
new = ( old | 3 );
outport( 97, new ); /* start speaker */
while( count++ < duration ) /* delay while speak makes tone */
;
outport( 97, old ); /* stop speaker */
return( 0 );
}
void main() /* a quickie demo... */
{
int i;
beep( 200, 10000 );
for( i = 0; i <= 2000; i++ );
beep( 400, 10000 );
for( i = 0; i <= 2000; i++ );
beep( 600, 10000 );
for( i = 0; i <= 2000; i++ );
beep( 800, 10000 );
for( i = 0; i <= 2000; i++ );
beep( 1000, 50 );
for( i = 0; i <= 2000; i++ );
beep( 2000, 10000 );
for( i = 0; i <= 2000; i++ );
beep( 3000, 10000 );
for( i = 0; i <= 2000; i++ );
beep( 4000, 10000 );
for( i = 0; i <= 2000; i++ );
beep( 5000, 10000 );
for( i = 0; i <= 2000; i++ );
beep( 6000, 10000 );
for( i = 0; i <= 2000; i++ );
}
/* OOPS - I see my TurboC 1.5 does include a 'sound()' and 'nosound()'!
* Oh well - at least the above code works without having to include
* "conio.h" in the source code. In any case, if you're working with 1.0
* this code my still be useful...
*/